package user

import (
	"news_for_deepseek_interface/controller"
	"news_for_deepseek_interface/dto"
	userDto "news_for_deepseek_interface/dto/admin/system/user"
	userService "news_for_deepseek_interface/service/admin/system/user"

	"github.com/gin-gonic/gin"
)

func Update(c *gin.Context) {
	// 1. 参数绑定
	var params userDto.UpdateRequest
	if err := c.ShouldBindJSON(&params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	// 2. 验证参数
	if err := dto.Validate(params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	// 3. 调用服务层处理
	if err := userService.Update(params); err != nil {
		controller.Fail(c, controller.BusinessError, err.Error())
		return
	}

	controller.Success(c, nil)
}
